<?php
class MedicineUsage extends ORDataObject {

	var $id = '';
	var $name = '';
	
	var $_key = 'id';
	var $_table = 'medicine_usage';
	var $_internalName = 'MedicineUsage';

	public function MedicineUsage($db = null) {
		parent::ORDataObject($db);
	}
	
	public function addUsage($name){
		$sql = array (
			'name' => $name
		);
		$this->populateArray($sql);		
		$this->persist();
	}
	
	public function getAllUsages(){
		$ds = new Datasource_sql();
		$sql = array (
			'cols' 		=> "name",
			'from'		=> "$this->_table"
		);
		$ds->setup($this->_db, $sql);
		return $ds->toArray('name');
	}
	
	public function isExist($name){
		$ds = new Datasource_sql();
		$sql = array (
			'cols' 		=> "id",
			'from'		=> "$this->_table",
			'where'		=> "name = '".$name."'"
		);
		$ds->setup($this->_db, $sql);
		$result = $ds->toArray();
		if (sizeof($result) == 0) return false;
		else return true;	
	}
}
?>